package com.dorm.cj.design.demo;

import com.dorm.cj.design.JsonMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.math.BigDecimal;

public class Test {
    public static Dog dog;

    static {
        dog = new Dog();
        dog.setAge(1);
        dog.setDogName("xiaobai");
        dog.setWeight(new BigDecimal(12.3).setScale(1, BigDecimal.ROUND_HALF_UP));
        dog.setXDogName("ssss");
    }

    public static void main(String[] args) throws IOException {

        ObjectMapper mapper = new ObjectMapper();
        String dogjsonstr = mapper.writeValueAsString(dog);

        System.out.println(dogjsonstr);
        Dog dog = mapper.readValue(dogjsonstr, Dog.class);
        System.out.println(dog.toString());
        System.out.println("=============默认mapper========================");

        String myjsonstr = JsonMapper.JSON_MAPPER_NON_EMPTY.toJson(Test.dog);
        System.out.println(myjsonstr);
        Dog dog2 = JsonMapper.JSON_MAPPER_NON_EMPTY.fromJson(myjsonstr, Dog.class);
        System.out.println(dog2.toString());
        System.out.println("=============自定义mapper=========================");
    }
}
